<template>
  <div>
    <el-scrollbar>
      <header
        style="
          display: flex;
          margin-bottom: -0.5%;
          justify-content: space-between;
        "
      >
        <h1>半自动人工调参</h1>
        <div>
          <el-button
            type="primary"
            style="
              margin-right: 20px;
              margin-top: -3px;
              height: 35px;
              font-size: 18px;
              background-color: #595959;
            "
            @click="back"
            >返回上一页</el-button
          >
        </div>
      </header>
      <div
        style="
          width: 100%;
          display: flex;
          justify-content: center;
          margin-top: 10px;
          flex-direction: column;
          align-items: center;
        "
      >
        <div style="display: flex; width: 95%; align-items: center">
          <el-tag>Tips：点击表格内容可进行数据修改</el-tag>
          <el-button link @click="copyTableData">
            <el-tag type="warning">复制到剪切板</el-tag>
          </el-button>
        </div>
        <div style="width: 100%; display: flex; justify-content: center">
          <el-table
            :data="firstTableData"
            style="width: 47%; margin-top: 10px"
            max-height="400px"
            stripe
            border
          >
            <el-table-column
              type="index"
              align="center"
              label="序号"
              width="60"
            >
              <template #default="{ $index }">
                {{ $index + 1 }}
              </template>
            </el-table-column>
            <el-table-column
              prop="label"
              label="参数名"
              align="center"
            ></el-table-column>
            <el-table-column prop="value" label="解值" align="center">
              <template #default="scope">
                <el-popover
                  v-model:visible="scope.row.visible"
                  placement="top"
                  width="200"
                  trigger="manual"
                >
                  <el-input
                    v-model="scope.row.value"
                    @blur="handleBlur(scope.$index, scope.row.prop)"
                  ></el-input>
                  <template #reference>
                    <div @click.stop="toggleInput(scope.row)">
                      {{ scope.row.value }}
                    </div>
                  </template>
                </el-popover>
              </template>
            </el-table-column>
          </el-table>
          <el-table
            :data="secondTableData"
            style="width: 47%; margin-top: 10px"
            max-height="400px"
            stripe
            border
          >
            <el-table-column
              type="index"
              align="center"
              label="序号"
              width="60"
            >
              <template #default="{ $index }">
                {{ $index + 9 }}
              </template>
            </el-table-column>
            <el-table-column
              prop="label"
              label="参数名"
              align="center"
            ></el-table-column>
            <el-table-column prop="value" label="解值" align="center">
              <template #default="scope">
                <el-popover
                  v-model:visible="scope.row.visible"
                  placement="top"
                  width="200"
                  trigger="manual"
                >
                  <el-input
                    v-model="scope.row.value"
                    @blur="handleBlur(scope.$index, scope.row.prop)"
                  ></el-input>
                  <template #reference>
                    <div @click.stop="toggleInput(scope.row)">
                      {{ scope.row.value }}
                    </div>
                  </template>
                </el-popover>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <div
        style="
          width: 100%;
          display: flex;
          justify-content: center;
          margin-top: 20px;
        "
      >
        <el-card style="width: 45%">
          <div style="width: 100%">
            <el-header
              style="
                font-size: 18px;
                display: flex;
                width: 100%;
                justify-content: space-between;
                align-items: center;
              "
            >
              <div
                style="
                  font-size: 18px;
                  width: 100%;
                  display: flex;
                  align-items: center;
                  justify-content: space-between;
                "
              >
                <strong>AI模型预测 </strong>
              </div>
              <el-button
                type="primary"
                style="background-color: #003f82"
                @click="getAIeval1"
                >开始预测</el-button
              >
            </el-header>
            <el-table stripe border style="margin-top: 10px" :data="response1">
              <el-table-column
                align="center"
                label="开始时间"
                prop="begin_time"
                width="180"
              ></el-table-column>
              <el-table-column
                align="center"
                label="结束时间"
                prop="end_time"
                width="180"
              ></el-table-column>
              <el-table-column
                align="center"
                label="方法耗时"
                prop="cost_time"
                width="120"
              ></el-table-column>
              <el-table-column
                align="center"
                label="验证信息"
                prop="content"
              ></el-table-column>
            </el-table>
          </div>
        </el-card>
        <el-card style="width: 54%; margin-left: 0.5%">
          <div style="width: 100%">
            <el-header
              style="font-size: 18px; display: flex; align-items: center"
            >
              <div
                style="
                  font-size: 18px;
                  width: 100%;
                  display: flex;
                  align-items: center;
                "
              >
                <strong>人工调参-仿真验证 </strong>
              </div>
              <div
                style="
                  display: flex;
                  align-items: center;
                  width: 100%;
                  margin-left: -20px;
                "
              >
                <span style="margin-right: 0">常规仿真：</span>
                <el-select
                  style="width: 60px"
                  v-model="selectedValue"
                  placeholder="默认是"
                >
                  <el-option
                    v-for="label in labels"
                    :key="label.key"
                    :label="label.value"
                    :value="label.key"
                  >
                  </el-option>
                </el-select>
              </div>
              <div
                v-if="selectedValue1 === 0"
                style="display: flex; align-items: center; width: 100%"
              >
                <span style="margin-right: -5px; margin-left: -10px"
                  >蒙卡采样次数：</span
                >
                <el-input
                  readonly
                  disabled
                  style="width: 60px"
                  v-model="selectedValue1"
                >
                </el-input>
              </div>
              <div
                v-else
                style="display: flex; align-items: center; width: 100%"
              >
                <span style="margin-right: -5px; margin-left: -10px"
                  >蒙卡采样次数：</span
                >
                <el-input style="width: 60px" v-model="selectedValue1">
                </el-input>
              </div>
              <el-button v-if="idShowButton" @click="goToDetail"
                >显示解详情</el-button
              >
              <el-button
                type="primary"
                style="background-color: #003f82"
                @click="getSingleSMEval1"
                >开始验证</el-button
              >
            </el-header>
            <div
              style="
                width: 100%;
                margin-right: 20px;
                display: flex;
                align-items: center;
                justify-content: center;
              "
            >
              <el-checkbox
                :disabled="!case11Selected"
                :title="case1SelectedDesc"
                v-model="case1Selected"
                :label="`issue1_陡降RA issue（55D17-1）`"
              />
              <!-- <el-checkbox  :disabled="!case11Selected" v-else v-model="case1Selected" :label="`issue1_陡降RA issue（55D17-1）`" /> -->
              <el-checkbox
                :disabled="!case22Selected"
                :title="case2SelectedDesc"
                v-model="case2Selected"
                :label="`issue2_骤降RA issue（55D17-2）`"
              />
              <!-- <el-checkbox  :disabled="!case22Selected" v-else  v-model="case2Selected" :label="`issue2_骤降RA issue（55D17-2）`" /> -->
              <el-checkbox
                :disabled="!case33Selected"
                :title="case3SelectedDesc"
                v-model="case3Selected"
                :label="`issue3_PWQ上限RA验证`"
              />
              <!-- <el-checkbox  :disabled="!case33Selected" v-else  v-model="case3Selected" :label="`issue3_PWQ上限RA验证`" /> -->
            </div>
            <el-table stripe border style="margin-top: 10px" :data="response2">
              <el-table-column
                align="center"
                label="开始时间"
                prop="begin_time"
                width="180"
              ></el-table-column>
              <el-table-column
                align="center"
                label="结束时间"
                prop="end_time"
                width="180"
              ></el-table-column>
              <el-table-column
                align="center"
                label="方法耗时"
                prop="cost_time"
                width="120"
              ></el-table-column>
              <el-table-column
                align="center"
                label="验证信息"
                prop="content"
              ></el-table-column>
            </el-table>
          </div>
        </el-card>
      </div>
      <el-row style="width: 100%; display: flex; flex-direction: row">
        <div style="width: 48.2%">
          <el-header
            style="
              font-size: 18px;
              display: flex;
              width: 100%;
              justify-content: space-between;
              align-items: center;
            "
          >
            <div
              style="
                font-size: 18px;
                width: 100%;
                display: flex;
                align-items: center;
                justify-content: space-between;
              "
            >
              <strong>获取AI模型预测结果 </strong>
            </div>
            <el-button
              type="primary"
              style="background-color: #003f82"
              @click="getAIEvalResult"
              >查询</el-button
            >
          </el-header>

          <el-table
            stripe
            border
            :data="tableResultData"
            max-height="400px"
            style="width: 100%; margin-top: 10px"
          >
            <el-table-column
              align="center"
              prop="key"
              label="预测项"
              width="280"
            ></el-table-column>
            <el-table-column
              align="center"
              prop="value0"
              label="预测值"
            ></el-table-column>
            <el-table-column
              align="center"
              prop="value1"
              label="预测方差"
            ></el-table-column>
          </el-table>
        </div>
        <div style="width: 51%; margin-left: 0.5%">
          <el-header
            style="
              font-size: 18px;
              display: flex;
              width: 100%;
              justify-content: space-between;
              align-items: center;
            "
          >
            <div
              style="
                font-size: 18px;
                width: 100%;
                display: flex;
                align-items: center;
              "
            >
              <strong>获取仿真验证结果 </strong>
              <el-tag>Tips：点击未显示完全内容可查看详情</el-tag>
            </div>
            <el-button
              type="primary"
              style="background-color: #003f82"
              @click="getsingleSMEvalRsult"
              >查询</el-button
            >
          </el-header>
          <el-table
            max-height="400px"
            @row-click="handleRowClick"
            :data="tableSMResultData"
            border
            stripe
            style="width: 100%; margin-top: 10px"
          >
            <el-table-column
              align="center"
              prop="key"
              label="验证项"
              width="280"
            ></el-table-column>
            <el-table-column align="center" prop="value" label="验证值">
              <template #default="scope">
                <div
                  class="ellipsis"
                  v-if="
                    Array.isArray(scope.row.value) && scope.row.value.length > 1
                  "
                >
                  {{ scope.row.value[0] }}...
                </div>
                <div class="ellipsis" v-else>
                  {{ scope.row.value }}
                </div>
              </template>
            </el-table-column>
          </el-table>

          <el-dialog
            style="margin-top: 2.4%; width: 60%"
            custom-class="custom-dialog"
            v-model="dialogVisible"
            title="列表详情"
          >
            <el-table
              stripe
              border
              max-height="800px"
              :data="formattedData"
              style="width: 100%; margin-top: 10px"
            >
              <el-table-column
                align="center"
                prop="key"
                label="列表项"
                width="280"
              ></el-table-column>
              <el-table-column align="center" label="对应值">
                <template #default="scope">
                  <ul>
                    <template
                      v-if="isForEach"
                      v-for="(value, key) in scope.row.values"
                      :key="key"
                    >
                      <span v-if="key && key != 'value' && isNaN(Number(key))">
                        {{ key }} ： {{ value }}
                      </span>
                      <span v-else>
                        {{ value }}
                      </span>
                    </template>
                    <li
                      v-if="!isForEach"
                      v-for="(value, key) in scope.row.values"
                      :key="key"
                    >
                      <span v-if="key && key != 'value' && isNaN(Number(key))">
                        {{ key }} ： {{ value }}
                      </span>
                      <span v-else>
                        {{ value }}
                      </span>
                    </li>
                  </ul>
                </template>
              </el-table-column>
            </el-table>
          </el-dialog>
        </div>
      </el-row>
    </el-scrollbar>
  </div>
</template>

<script setup name="半自动人工调参">
import { useStore } from "vuex";
import {
  watch,
  ref,
  onMounted,
  onUnmounted,
  computed,
  defineProps,
  onActivated,
} from "vue";
import { ElMessage } from "element-plus";
import router from "@/router/index.js";
import useUserInfoStore from "@/stores/userInfo.js";
import {
  singleSMEvalEval,
  AIEval,
  AIEvalResult,
  singleSMEval,
  singleSMEvalRsult,
} from "@/server/AiScore";
const store = useStore();
const aiScoreData = computed(() => store.state.aiScoreData);
watch(aiScoreData, (newData) => {
  if (newData) {
    updatePageData(newData);
  }
});
const updatePageData = (data) => {
  console.log(data);
  response1.value = [];
  response2.value = [];
  tableSMResultData.value = [];
  tableResultData.value = [];
  circuitDiagramName.value = data.circuit_diagram_name;
  const transformedData = columns.map((column) => ({
    label: column.label,
    value: data[column.prop],
    prop: column.prop,
    visible: false,
  }));
  tableData.value = transformedData;
  console.log(tableData.value);
  firstTableData.value = transformedData.slice(0, 8);
  secondTableData.value = transformedData.slice(8);
  getStateEval();
};
onMounted(() => {
  if (props.rowData) {
    circuitDiagramName.value = props.rowData.circuit_diagram_name;
    const transformedData = columns.map((column) => ({
      label: column.label,
      value: props.rowData[column.prop],
      prop: column.prop,
      visible: false,
    }));
    tableData.value = transformedData;
    firstTableData.value = transformedData.slice(0, 8);
    secondTableData.value = transformedData.slice(8);
  }
  getStateEval();
});
const idShowButton = ref(true);
const goToDetail = () => {
  constParams();
  router.push({
    name: "参数结果查询",
    query: {
      rowData1: JSON.stringify(params),
    },
  });
};

const userInfoStore = useUserInfoStore();
const userInfo = userInfoStore.info;

const tableData = ref([]);
const back = () => {
  router.back();
};
const props = defineProps({
  rowData: Object,
});
const columns = [
  {
    prop: "A11",
    label: "A11",
    width: "180",
  },
  {
    prop: "A21",
    label: "A21",
    width: "180",
  },
  {
    prop: "A22",
    label: "A22",
    width: "180",
  },
  {
    prop: "A32",
    label: "A32",
    width: "180",
  },
  {
    prop: "A41",
    label: "A41",
    width: "180",
  },
  {
    prop: "A42",
    label: "A42",
    width: "180",
  },
  {
    prop: "A44",
    label: "A44",
    width: "180",
  },
  {
    prop: "A51",
    label: "A51",
    width: "180",
  },
  {
    prop: "A52",
    label: "A52",
    width: "180",
  },
  {
    prop: "A53",
    label: "A53",
    width: "180",
  },
  {
    prop: "A54",
    label: "A54",
    width: "180",
  },
  {
    prop: "A55",
    label: "A55",
    width: "180",
  },
  {
    prop: "A56",
    label: "A56",
    width: "180",
  },
  {
    prop: "A72",
    label: "A72",
    width: "180",
  },
  {
    prop: "Cb",
    label: "Cb",
    width: "180",
  },
];

const firstTableData = ref([]);
const secondTableData = ref([]);

const labels = ref([
  { key: 1, value: "是" },
  { key: 0, value: "否" },
]);
const selectedValue = ref(1);
const selectedValue1 = ref(null);

const toggleInput = (row) => {
  tableData.value.forEach((r) => {
    r.visible = false;
  });
  row.visible = true;
};

const handleBlur = (index) => {
  tableData.value[index].visible = false;
};

const getStateEval = async () => {
  try {
    const respose = await singleSMEvalEval({
      user: userInfo,
      circuit_diagram_name: props.rowData.circuit_diagram_name,
    });
    selectedValue1.value = respose.valid_MC;
    case1Selected.value = respose.valid_issue1 !== 0;
    case2Selected.value = respose.valid_issue2 !== 0;
    case3Selected.value = respose.valid_issue3 !== 0;
    case11Selected.value = respose.valid_issue1 !== 0;
    case22Selected.value = respose.valid_issue2 !== 0;
    case33Selected.value = respose.valid_issue3 !== 0;
    case1SelectedDesc.value = respose.valid_issue1_desc;
    case2SelectedDesc.value = respose.valid_issue2_desc;
    case3SelectedDesc.value = respose.valid_issue3_desc;
    let missingFiles = [];
    let isMissing = false;
    if (respose.valid_MC === 0) {
      missingFiles.push("蒙卡配置文件");
      isMissing = true;
    }
    if (respose.valid_issue1 === 0) {
      missingFiles.push("issue1_陡降RA issue（55D17-1）");
      isMissing = true;
    }
    if (respose.valid_issue2 === 0) {
      missingFiles.push("issue2_骤降RA issue（55D17-2）");
      isMissing = true;
    }
    if (respose.valid_issue3 === 0) {
      missingFiles.push("issue3_PWQ上限RA验证");
      isMissing = true;
    }
    if (isMissing) {
      confirm(
        `请注意，当前电路，缺少以下配置文件，这可能会影响蒙卡验证或案例，缺失文件配置: ${missingFiles.join(
          ", "
        )}`
      );
    }
  } catch (e) {
    console.error(e);
  }
};

const case1Selected = ref(false);
const case2Selected = ref(false);
const case3Selected = ref(false);
const case11Selected = ref(false);
const case22Selected = ref(false);
const case33Selected = ref(false);
const case1SelectedDesc = ref(null);
const case2SelectedDesc = ref(null);
const case3SelectedDesc = ref(null);

const getAIeval1 = () => {
  const isConfirm = confirm(
    "点击预测按钮将会开始预测，每5秒会自动更新一次数据"
  );
  if (isConfirm) {
    getAIEval();
  } else {
    ElMessage.info("取消操作");
  }
};
const getSingleSMEval1 = () => {
  const isConfirm = confirm("是否开始验证");
  if (isConfirm) {
    getSingleSMEval();
  } else {
    ElMessage.info("取消操作");
  }
};

const tableResultData = ref([]);
const getAIEvalResult = async () => {
  constParams();
  try {
    const response = await AIEvalResult(params);
    console.log(response);
    if (response.content != "计算完毕") {
      confirm("任务不存在或任务正在计算中，请稍后再进行查询");
      ElMessage.error("操作失败！");
      return;
    }
    tableResultData.value = Object.entries(response)
      .filter(
        ([key]) =>
          key !== "begin_time" &&
          key !== "content" &&
          key !== "cost_time" &&
          key !== "end_time" &&
          key !== "status"
      )
      .flatMap(([key, value]) => {
        if (Array.isArray(value) && value.length === 2) {
          return [{ key: `${key}`, value0: value[0], value1: value[1] }];
        } else {
          return { key, value };
        }
      });
  } catch (e) {
    console.error("e:", e);
    confirm("任务不存在或任务正在计算中，请稍后再进行查询");
    ElMessage.error("操作失败！");
  }
};

const tableSMResultData = ref([]);
const getsingleSMEvalRsult = async () => {
  constParams();
  try {
    params.EV = selectedValue.value;
    params.MC = selectedValue1.value;
    params.issue1 = case1Selected.value ? 1 : 0;
    params.issue2 = case2Selected.value ? 1 : 0;
    params.issue3 = case3Selected.value ? 1 : 0;
    const response = await singleSMEvalRsult(params);
    console.log(response);
    if (response.status !== "success") {
      confirm("任务不存在或任务正在计算中，请稍后再进行查询");
      ElMessage.error("操作失败！");
      return;
    }
    tableSMResultData.value = Object.entries(response)
      .filter(
        ([key]) =>
          key !== "begin_time" &&
          key !== "content" &&
          key !== "cost_time" &&
          key !== "end_time" &&
          key !== "status"
      )
      .map(([key, value]) => ({ key, value }));
    const ignoredFields = [
      "begin_time",
      "content",
      "cost_time",
      "end_time",
      "status",
    ];
    for (const key in response) {
      if (!response.hasOwnProperty(key)) continue;
      if (ignoredFields.includes(key)) continue;
      if (response.hasOwnProperty(key) && typeof response[key] === "string") {
        try {
          const parsedValue = JSON.parse(response[key]);
          response[key] = parsedValue;
          errorList.value[key] = parsedValue;
          console.log(response[key], "json数据");
        } catch (e) {
          (errorList.value[key] = response[key]),
            console.log(response[key], "并非json数据");
        }
      }
    }
  } catch (e) {
    console.error("e:", e);
    confirm("任务不存在或任务正在计算中，请稍后再进行查询");
    ElMessage.error("操作失败！");
  }
};

const isForEach = ref(false);
const dialogVisible = ref(false);
const errorList = ref([]);
const formattedData = computed(() => {
  if (dialogVisible.value && currentRowData.value) {
    const currentData = errorList.value[currentRowData.value.key];
    console.log(currentData);
    if (typeof currentData === "string" && currentData === "任务不存在") {
      isForEach.value = true;
      return [{ key: "", values: currentData }];
    }

    if (typeof currentData === "object" && currentData !== null) {
      return Object.entries(currentData).map(([key, values]) => {
        isForEach.value = false;
        return {
          key,
          values: typeof values === "object" ? values : { value: values },
        };
      });
    }
  }
  return [];
});

watch(dialogVisible, (newValue) => {
  if (!newValue) {
    currentRowData.value = null; // 当对话框关闭时，清除当前行数据
  }
});

const currentRowData = ref(null);

function handleRowClick(row) {
  if (
    row.key != "总得分" &&
    row.key != "vth负偏margin" &&
    row.key != "vth正偏margin" &&
    row.key != "vth负偏margin" &&
    row.key != "vgh margin" &&
    row.key != "issue3_vgh_margin得分" &&
    row.key != "issue2_vgh_margin得分"
  ) {
    currentRowData.value = row;
    dialogVisible.value = true;
  }
}
const circuitDiagramName = ref("");
let params = {};
function constParams() {
  // 清空 params 对象
  for (let key in params) {
    if (Object.prototype.hasOwnProperty.call(params, key)) {
      delete params[key];
    }
  }

  params.user = userInfo;
  if (circuitDiagramName.value !== "") {
    params.circuit_diagram_name = circuitDiagramName.value;
  } else {
    params.circuit_diagram_name = props.rowData.circuit_diagram_name;
  }
  firstTableData.value.forEach((row) => {
    params[row.label] = row.value;
  });
  secondTableData.value.forEach((row) => {
    params[row.label] = row.value;
  });
}

const copyTableData = () => {
  let textToCopy = "";
  firstTableData.value.forEach((item) => {
    textToCopy += `.PARAM ${item.label}=${item.value}\n\n`;
  });
  // 处理第二张表数据
  secondTableData.value.forEach((item) => {
    textToCopy += `.PARAM ${item.label}=${item.value}\n\n`;
  });
  const textarea = document.createElement("textarea");
  textarea.value = textToCopy;
  document.body.appendChild(textarea);
  textarea.select();
  document.execCommand("copy");
  document.body.removeChild(textarea);

  // 显示复制成功的消息
  ElMessage({
    message: "复制成功！",
    type: "success",
  });
};

/* --------------计时器相关代码---------------------- */
const response1 = ref([]);
const response2 = ref([]);

const getAIEval = async () => {
  constParams();
  if (timerId.value == null) {
    startTimer();
  }
  let formatDates = (time) => {
    if (time !== "-" && time) {
      time = Number(time);
      if (time < 1000) {
        return time.toFixed(2) + "ms";
      } else if (time < 60000) {
        return (time / 1000).toFixed(2) + "s";
      } else {
        const minutes = Math.floor(time / 60000);
        const seconds = ((time % 60000) / 1000).toFixed(2);
        return minutes + "min " + seconds + "s";
      }
    } else {
      return "-";
    }
  };
  console.log(userInfo);
  try {
    const response = await AIEval(params);
    const formattedResponse = {
      begin_time: formatDate(response.begin_time),
      end_time: formatDate(response.end_time),
      content:
        response.content !== undefined && response.content !== null
          ? response.content
          : "-",
      cost_time: formatDates(response.cost_time),
    };
    response1.value = [formattedResponse]; // 将单个对象包装成数组
    if (response.content != "计算中") {
      stopTimer();
    }
  } catch (e) {
    ElMessage.error("操作失败");
    stopTimer();
    console.error("e:", e);
  }
};

const formatDate = (time) => {
  if (time !== "-" && time) {
    let date = new Date(Number(time));
    return date
      .toLocaleString("zh-CN", {
        hour12: false,
        year: "numeric",
        month: "2-digit",
        day: "2-digit",
        hour: "2-digit",
        minute: "2-digit",
      })
      .replace(/,/g, " ")
      .slice(5); // 只显示月时分
  } else {
    return "-";
  }
};
const timerId = ref(null);
const totalSeconds = ref(0);

function startTimer() {
  console.log("调用了startTimer2");
  timerId.value = setInterval(() => {
    totalSeconds.value++;
    if (totalSeconds.value % 5 === 0) {
      getAIEval();
    }
  }, 1000);
}

function stopTimer() {
  if (timerId.value) {
    clearInterval(timerId.value);
    timerId.value = null;
  }
}
const getSingleSMEval = async () => {
  constParams();

  if (timerId1.value == null) {
    startTimer1();
  }
  let formatDates = (time) => {
    if (time !== "-" && time) {
      time = Number(time);
      if (time < 1000) {
        return time.toFixed(2) + "ms";
      } else if (time < 60000) {
        return (time / 1000).toFixed(2) + "s";
      } else {
        const minutes = Math.floor(time / 60000);
        const seconds = ((time % 60000) / 1000).toFixed(2);
        return minutes + "min " + seconds + "s";
      }
    } else {
      return "-";
    }
  };
  console.log(userInfo);
  try {
    params.EV = selectedValue.value;
    params.MC = selectedValue1.value;
    params.issue1 = case1Selected.value ? 1 : 0;
    params.issue2 = case2Selected.value ? 1 : 0;
    params.issue3 = case3Selected.value ? 1 : 0;
    const response = await singleSMEval(params);
    const formattedResponse = {
      begin_time: formatDate(response.begin_time),
      end_time: formatDate(response.end_time),
      content:
        response.content !== undefined && response.content !== null
          ? response.content
          : "-",
      cost_time: formatDates(response.cost_time),
    };
    response2.value = [formattedResponse]; // 将单个对象包装成数组
    if (response.content !== "计算中") {
      stopTimer1();
    }
  } catch (e) {
    confirm("操作失败，您选中的案例可能不存在");
    ElMessage.error("操作失败");
    stopTimer1();
    console.error("e:", e);
  }
};
const timerId1 = ref(null);
const totalSeconds1 = ref(0);

function startTimer1() {
  console.log("调用了startTimer1");
  timerId1.value = setInterval(() => {
    totalSeconds1.value++;
    if (totalSeconds1.value % 5 === 0) {
      getSingleSMEval();
    }
  }, 1000);
}

function stopTimer1() {
  if (timerId1.value) {
    clearInterval(timerId1.value);
    timerId1.value = null;
  }
}
onUnmounted(() => {
  stopTimer();
  stopTimer1();
});
</script>

<style scoped>
.ellipsis {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  display: block;
  /* 确保元素为块级元素 */
}
.el-table .cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.custom-dialog .el-dialog {
  width: auto;
  /* 让宽度自适应内容 */
  max-width: 90%;
  /* 最大宽度限制 */
}
.el-checkbox {
  display: flex;
  margin: 4px;
}
</style>
